package cn.tedu._05mvcboot02.common.exception;

import cn.tedu._05mvcboot02.common.response.JsonResult;
import cn.tedu._05mvcboot02.common.response.StatuCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@Slf4j
@RestControllerAdvice
public class GlobalExceptionhandler {
    @ExceptionHandler
    public JsonResult doHandlerIllegalArgumentException(IllegalArgumentException ex){
        String data=ex.getMessage();
        log.error("IllegalArgumentException:"+data);
        return JsonResult.fail(data);
    }
    @ExceptionHandler
    public JsonResult doHandlerRuntimeException(RuntimeException ex){
        String data= ex.getMessage();
        log.error("RuntimeException:"+data);
        return JsonResult.fail(data);
    }
    @ExceptionHandler
    public JsonResult ThrowHandler(Throwable throwable){
        String data=throwable.getMessage();
        log.error("Throwable:"+data);
        return new JsonResult(StatuCode.THROWABLE_ERROR,data);
    }
}
